home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 April: Mac OS SDK / Dev.CD Apr 97 SDK1.toast / Development Kits (Disc 1) / Installer SDK Cornucopia 1.0.2 / Script Examples / Rule Function [inrf] Example / myRuleFunction.r < prev    next >
Encoding:
Text File  |  1996-09-30  |  5.2 KB  |  174 lines  |  [TEXT/MPS ]

  1. //
  2. //    myRuleFunction.r
  3. //
  4. //        This example installs a "ReadMe" file to the folder
  5. //        'Rule Function Example:' at the root of the selected target volume.
  6. //
  7. //        This example script uses a Rule Function to check the version of
  8. //        the currently running operating system.
  9. //
  10. //        NOTE:  This is different from using an Installer "CheckFileVersion" call.
  11. //        When "CheckFileVersion" is used to check the System version, the
  12. //        target System file spec ('intf') supplied refers to the System file
  13. //        in the directory "special-macs".  That is the System file in the 
  14. //        blessed system folder on the _target HD_.  Since users may have
  15. //        different versions of system folders on different hard disks, the
  16. //        boot volume may not be the target volume; thus, this is not
  17. //        necessarily checking the version of the currently running operating
  18. //        system!
  19. //
  20. //        In addition, if no blessed system folder is found on the target volume, 
  21. //        the path "special-macs:" will default to ":System Folder:".
  22. //        In the case where the user has removed the Finder file from folder named
  23. //        "System Folder" that still contains a copy of the System file, the 
  24. //        "CheckFileVersion" check for an existing System version on the target
  25. //        volume may be erroneous.  (To avoid this, you could verify the existence
  26. //        of both a System and Finder in "special-macs:" before you attempted to
  27. //        check the System file version.)
  28. //
  29. //        Copyright 1993-1996, Apple Computer, Inc., All Rights Reserved
  30. //
  31.  
  32. #include "InstallerTypes.r"
  33.  
  34. // include the file containing our Rule Function code resource item
  35. // - note that since this external file is in the form of a file containing
  36. // already compiled resources, that the include line does not use '#include' 
  37. // and that it is terminated with a semicolon.
  38.  
  39. include "DoRuleFunction.rsrc" 'infn' (128);
  40.  
  41. #define rlCheckSysVers        700
  42. #define rlBadSysVers        800
  43.  
  44. #define rfCheckSystemVers    128
  45.  
  46.                                             // easy install framework uses ID other than 765 or 766
  47.                                             // recommended to always use ID 764
  48. resource 'infr' (764) {
  49.     format0 {{
  50.                                             // execute first true rule
  51.                                             // if none are true then return false
  52.         pickFirst, { rlCheckSysVers,         // check system version, 
  53.                       rlBadSysVers},         //  if bad give error
  54.     }}
  55. };
  56.  
  57.                                             // rule that adds 7.5 or greater compatable file to Easy Install
  58. resource 'inrl' (rlCheckSysVers) {
  59.     format0 {{
  60.                                                 // check for 7.5 or greater
  61.         CheckRuleFunction{ rfCheckSystemVers },
  62.         
  63.                                                 // if 7.5 or greater add that package
  64.         AddPackages{{ 100 }},
  65.         AddUserDescription{ "Rule Function Returned: TRUE.\n  System version is 7.5 or greater." },
  66.     }}
  67. };
  68.  
  69.                                             // rule that displays error if system is earlier than 7.5
  70. resource 'inrl' (rlBadSysVers) {
  71.     format0 {{
  72.         reportSysError {"Rule Function returned: FALSE.\n System version 7.5 or greater is required."},
  73.     }}
  74. };
  75.  
  76. resource 'inpk' (100) {
  77.     format0 {
  78.         doesntShowOnCustom,
  79.         removable,
  80.         dontForceRestart,
  81.         0,
  82.         0,
  83.         "ReadMe to “Rule Function Example” folder",
  84.         {    
  85.         'infa', 1000    // file atom 
  86.         },
  87.     }
  88. };
  89.  
  90. resource 'infa' (1000) {
  91.     format1 {
  92.         deleteWhenRemoving,
  93.         deleteWhenInstalling,
  94.         copy,                            
  95.         dontIgnoreLockedFile,
  96.         dontSetFileLocked,
  97.         useSrcCrDateToCompare,            //  • Use creation date for compare
  98.         srcNeedNotExist,
  99.         rsrcForkInRsrcFork,
  100.         leaveAloneIfNewer,                //  • Do not update a newer file
  101.         updateExisting,                    
  102.         copyIfNewOrUpdate,
  103.         rsrcFork,
  104.         dataFork,
  105.         0,
  106.         0x0,
  107.         10000,                            // target file spec
  108.         {    
  109.             20000,                         // source file spec
  110.             0, 
  111.             0    
  112.         },
  113.         
  114.         0,                                // version number filled in by ScriptCheck
  115.         0,                                // no vers proc.
  116.         0,                                // no atom extender
  117.         "Example File"
  118.         }
  119.     };
  120.  
  121. resource 'inrf' (128, "Check currently running System version"){
  122.         format0 {
  123.                 'infn',                    // Rule Function Code Rsrc Type   NOTE:  code rsrc has C calling interface.
  124.                 128,                    // Rule Function Code Rsrc ID 
  125.                 0,                        // RefCon Value 
  126.                 24000,                    // Requested Memory in bytes 
  127.                 "Checking active System version"// Optional Summary String, not shown to user //    
  128.         };
  129. };
  130.  
  131. include "Alert.rsrc";                    // alert used by rule function code
  132.  
  133. // target file spec for ReadMe file
  134. resource 'intf' (10000) {
  135.     format1 {
  136.         noSearchForFile,                 // use default search path
  137.         
  138.         TypeCrMustMatch,                 // If this is set to TypeCrMustMatch
  139.                                         // then a file with a different type
  140.                                         // and creator than those specified
  141.                                         // below will not be replaced.
  142.                                         // If this is set to TypeCrNeedNotMatch
  143.                                         // then type and creator of an existing
  144.                                         // target file are ignored.
  145.         
  146.         // The Type and Creator fields will be used to set the
  147.         // file's Type and Creator when a new file is created. 
  148.         'ttro',                         // TYPE for new file
  149.         'ttxt',                         // CREATOR for new file
  150.         
  151.         0,                                 // finder attribute flags
  152.                                         // filled by ScriptCheck is value is 0
  153.         
  154.         1,                                  // creation date for new file
  155.         1,                                  // modification date for new file
  156.                                         // NOTE: DATE values are filled
  157.                                         // by ScriptCheck if the value is 1
  158.                                             
  159.         0,                                 // search proc ID ( 'insp' ), none used
  160.         
  161.         ":Rule Function Example:Example File"    // path to target file
  162.         }
  163.     };
  164.  
  165. // source file spec for Example File file
  166. resource 'infs' (20000) {
  167.     'ttro',
  168.     'ttxt',
  169.     0x1,
  170.     noSearchForFile,
  171.     TypeCrMustMatch,
  172.     "Disk1:Example File"                            // path to source file
  173.     };
  174.